package com.example.idea.mapper;

import com.example.idea.entity.Dao.UserDao;
import com.example.idea.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    User add(User user);

    void update(User user);

    void delete(Integer id);

    User query(Integer id);

    void deleteBatch(List<Integer> ids);

    List<User> list();

    List<User> selectList(User user);

    List<User> selectListPage(User user);

    @Select("select * from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%') ORDER BY id DESC limit #{skipNum},#{pageSize}")
    List<User> selectByPage(@Param("skipNum") Integer skipNum, @Param("pageSize")Integer pageSize,@Param("username") String username,@Param("name") String name);

    @Select("select count(*) from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%')")
    Integer selectCountByPage(@Param("username") String username,@Param("name") String name);

    @Select("select * from user where username = #{username}")
    User selectByUserName(String username);

    @Select("select * from user where username = #{username}")
    User selectByUser(String username);

    @Select("select * from user where username = #{username}")
    UserDao selectByUserDao(String username);

    @Insert("insert into user(username,password,address,role,email,phone) values(#{username},#{password},#{address},#{role},#{email},#{phone})")
    int addPlusUser(User user);

    @Update("update user set password = #{password} where username = #{username}")
    void updateDao(UserDao userDao);

    @Select("select * from user where username like concat('%',#{username},'%') and name like concat('%',#{name},'%')")
    List<User> selectListAll(String username, String name);

    @Select("select * from user where id in (#{id})")
    List<User> selectByIds(List<Integer> id);

    @Insert("insert into user(username,name,password,address,role,avatar,email,phone) values(#{username},#{name},#{password},#{address},#{role},#{avatar},#{email},#{phone})")
    void addInfo(User userList);
}
